<template>
	<view class="content">
		<view class="logo">
			<image src="https://img14.weikeimg.com/data/uploads/2020/09/23/6789350955f6ae2d6ecb36.png" ></image>
		</view>
		<view class="item">
			<input  class="uni-input" type="number" v-model="work.telephone" placeholder="请输入账号..."  />
			<input  class="uni-input" password type="text" v-model="work.password"  placeholder="请输入密码..." />
		</view>
		<view class="button2">
			<button  type="primary" size="mini" @click="login()">登录</button>
		</view>
		<view class="qita">
			<view class="zhucu">
				<text>注册账户</text>
			</view>
			<view class="fanhui">
				<text @click="fanHuiShouYe()">返回首页</text>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
const work = ref({
	telephone:"",
	password:""
})



const login = ()=>{
	uni.request({
				url: `http://wtp.qywy.cc/users?telephone=${work.value.telephone}`,
				success: (res) => {
					if(res.data.length>0){
						if(res.data[0].password === work.value.password ){
							uni.setStorageSync("loginInfo",JSON.stringify(res.data[0]))
							uni.setStorageSync("id",res.data[0].id)
							uni.switchTab({
								url: '/pages/index/index'
							})
					
						}else{
							uni.showToast({
							    title: '密码错误',
							    duration: 2000,
								icon:"error"
							});
						}
					}else{
						uni.showToast({
						    title: '账户不存在',
						    duration: 2000,
							icon:"error"
						});
					}
	
				}
			});
	// fetch(`http://localhost:3000/users?telephone=${work.value.telephone}`,{
	//     method:'get'
	// }).then(response=>response.json()).then((data)=>{
	// 	if(data.length>0){
	// 		if(data[0].password === work.value.password ){
	// 			uni.setStorageSync("loginInfo",JSON.stringify(data[0]))
	// 			uni.setStorageSync("id",data[0].id)
	// 			uni.switchTab({
	// 				url: '/pages/index/index'
	// 			})

	// 		}else{
	// 			uni.showToast({
	// 			    title: '密码错误',
	// 			    duration: 2000,
	// 				icon:"error"
	// 			});
	// 		}
	// 	}else{
	// 		uni.showToast({
	// 		    title: '账户不存在',
	// 		    duration: 2000,
	// 			icon:"error"
	// 		});
	// 	}
	// })
}
// 返回首页
const fanHuiShouYe = ()=>{
	uni.switchTab({
		url: '/pages/index/index'
	})
}
	
	
</script>

<style scoped>
	.content{
		height: 400px;
		
	}
	.item{
		padding-top: 10px;
	}
   .uni-input{
	   width:300px;
	   height: 30px;
	   background-color: gainsboro;
	   margin-top: 10px;
	   margin-left: 50px;
   }
   .logo{
	   padding-top: 80px;
	   padding-left: 145px;
   }
   .logo image{
	   width: 90px;
	   height: 90px;
   }
   .button2 button{
	   height: 30px;
	   width: 280px;
	   margin-left: 60px;
	   margin-top: 30px;
   }
   .qita{
	   display: flex;
	   flex-direction: row;
   }
   .zhucu{
	   margin-left: 50px;
	   color: grey;
	   margin-top: 20px;
   }
   .fanhui{
	   color: grey;
	   margin-top: 20px;
	   margin-left: 180px;
   }
</style>
